home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / pvm34b3.zip / pvm34b3 / pvm3 / src / lmsg.c < prev    next >
C/C++ Source or Header  |  1997-07-22  |  4KB  |  178 lines

  1.  
  2. static char rcsid[] =
  3.     "$Id: lmsg.c,v 1.3 1997/06/25 22:08:50 pvmsrc Exp $";
  4.  
  5. /*
  6.  *         PVM version 3.4:  Parallel Virtual Machine System
  7.  *               University of Tennessee, Knoxville TN.
  8.  *           Oak Ridge National Laboratory, Oak Ridge TN.
  9.  *                   Emory University, Atlanta GA.
  10.  *      Authors:  J. J. Dongarra, G. E. Fagg, M. Fischer
  11.  *          G. A. Geist, J. A. Kohl, R. J. Manchek, P. Mucci,
  12.  *         P. M. Papadopoulos, S. L. Scott, and V. S. Sunderam
  13.  *                   (C) 1997 All Rights Reserved
  14.  *
  15.  *                              NOTICE
  16.  *
  17.  * Permission to use, copy, modify, and distribute this software and
  18.  * its documentation for any purpose and without fee is hereby granted
  19.  * provided that the above copyright notice appear in all copies and
  20.  * that both the copyright notice and this permission notice appear in
  21.  * supporting documentation.
  22.  *
  23.  * Neither the Institutions (Emory University, Oak Ridge National
  24.  * Laboratory, and University of Tennessee) nor the Authors make any
  25.  * representations about the suitability of this software for any
  26.  * purpose.  This software is provided ``as is'' without express or
  27.  * implied warranty.
  28.  *
  29.  * PVM version 3 was funded in part by the U.S. Department of Energy,
  30.  * the National Science Foundation and the State of Tennessee.
  31.  */
  32.  
  33. /*
  34.  *    lmsg.c
  35.  *
  36.  *    low level message functions.
  37.  *
  38.  */
  39.  
  40. #include <pvm3.h>
  41. #include "pvmalloc.h"
  42. #include "listmac.h"
  43. #include "pvmdabuf.h"
  44. #include "pvmmagic.h"
  45. #include "lmsg.h"
  46.  
  47.  
  48. extern void pvmbailout();
  49.  
  50.  
  51. /***************
  52.  **  Private  **
  53.  **           **
  54.  ***************/
  55.  
  56. #ifdef IMA_CSPP
  57.  
  58. /* NOTE:  If we were doing flushes on node, we'd have to set dcache_stride
  59.           to 32 for single node systems and 64 for multinode systems.
  60.           But since we only do this for cross node systems, we already know
  61.           it needs to be 64
  62. */
  63.  
  64. int dcache_stride = 64;
  65. #endif
  66.  
  67. #ifdef    CLUMP_ALLOC
  68. #ifndef    MSGID_CLUMP
  69. #define    MSGID_CLUMP 50
  70. #endif
  71. static struct msgid freemsgids;        /* free msgid header cache */
  72. static int nummsgids = 0;
  73. #endif
  74.  
  75.  
  76. static struct msgid *
  77. msgid_get_header()
  78. {
  79.     struct msgid *mp;
  80.     int n;
  81.  
  82. #ifdef    CLUMP_ALLOC
  83.     if (nummsgids == 0) {
  84.         freemsgids.ms_link = freemsgids.ms_rlink = &freemsgids;
  85.         if (!(mp = TALLOC(MSGID_CLUMP, struct msgid, "mids")))
  86.             return (struct msgid *)0;
  87.         for (n = MSGID_CLUMP; n-- > 0; ) {
  88.             LISTPUTBEFORE(&freemsgids, mp, ms_link, ms_rlink);
  89.             mp++;
  90.         }
  91.         nummsgids = MSGID_CLUMP;
  92.     }
  93.     nummsgids--;
  94.     mp = freemsgids.ms_link;
  95.     LISTDELETE(mp, ms_link, ms_rlink);
  96.  
  97. #else
  98.     mp = TALLOC(1, struct msgid, "mid");
  99. #endif
  100.  
  101.     mp->magic = LMSG_MSGID;  /* set the magic number */
  102.     return mp;
  103. }
  104.  
  105.  
  106. static
  107. msgid_put_header(mp)
  108.     struct msgid *mp;
  109. {
  110.  
  111.     if (BADMAGIC(LMSG_MSGID, mp->magic))
  112.     {
  113.         pvmlogerror("msgid_put_header(): bad magic number \n");
  114.         pvmbailout(0);
  115.         return PvmSysErr;
  116.     }            
  117. #ifdef    CLUMP_ALLOC
  118.     if (nummsgids == 0)
  119.         freemsgids.ms_link = freemsgids.ms_rlink = &freemsgids;
  120.     LISTPUTBEFORE(&freemsgids, mp, ms_link, ms_rlink);
  121.     nummsgids++;
  122.  
  123. #else
  124.     PVM_FREE(mp);
  125. #endif
  126.     return 0;
  127. }
  128.  
  129.  
  130. /**********************
  131.  **  Lmsg Functions  **
  132.  **                  **
  133.  **********************/
  134.  
  135. /*    msgid_new()
  136. *
  137. *    Create a new message id
  138. */
  139.  
  140. struct msgid *
  141. msgid_new()
  142. {
  143.     struct msgid *mp;
  144.  
  145.     if (!(mp = msgid_get_header()))
  146.         goto oops;
  147.  
  148.     mp->id = -1;
  149.     mp->otid = -1;
  150.     mp->ctxt = -1;
  151.     mp->complete = 0;
  152.     mp->ubuf = (char *) 0;
  153.  
  154.     return mp;
  155.  
  156.  
  157. oops:
  158.     pvmlogerror("msgid_new() can't get memory\n");
  159.     pvmbailout(0);
  160.     return (struct msgid *) 0;
  161. }
  162.  
  163.  
  164. /*    msgid_free()
  165. *
  166. *    free the msgid structure
  167. */
  168.  
  169. void
  170. msgid_free(mp)
  171.     struct msgid *mp;
  172. {
  173.         if (mp)
  174.             msgid_put_header(mp);
  175. }
  176.  
  177.  
  178.